﻿using System;
using System.Collections.Generic;
using System.Text;


namespace Magenic.CodeMastery.SharePoint.PMO
{
    public class CalendarHelper
    {
        private DayOfWeek firstDayOfWeek = DayOfWeek.Sunday;

        public CalendarHelper(DayOfWeek firstDayOfWeek)
        {
            this.firstDayOfWeek = firstDayOfWeek;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="anyDayInWeek"></param>
        /// <returns>The first day of the week containing the passed-in date.</returns>
        public DateTime FirstDayOfWeek(DateTime anyDayInWeek)
        {
            int offset = (int)firstDayOfWeek;
            offset -= (int)anyDayInWeek.DayOfWeek;
            if (offset > 0)
                offset -= 7;
            return anyDayInWeek.AddDays(offset);
        }
    }
}